AI Verified

Name

Add Country Prefix to Billing Phone on Woocomerce Chekout

Language

PHP

Rating

Voted: 0 by 0 user(s)

Codevault

Totalweb AS

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: Not Specified

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

13/11/2022

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Add Country Prefix to Billing Phone on Woocomerce Chekout

 
                    
1add_action( 'wp_footer', 'scripts_for_adding_country_prefix_on_billing_phone' );
2function scripts_for_adding_country_prefix_on_billing_phone(){
3 ?>
4 <script type="text/javascript">
5 ( function( $ ) {
6 $( document.body ).on( 'updated_checkout', function(data) {
7 var ajax_url = "<?php echo admin_url('admin-ajax.php'); ?>",
8 country_code = $('#billing_country').val();
9 var ajax_data = {
10 action: 'append_country_prefix_in_billing_phone',
11 country_code: $('#billing_country').val()
12 };
13 $.post( ajax_url, ajax_data, function( response ) {
14 $('#billing_phone').val(response);
15 });
16 } );
17 } )( jQuery );
18 </script>
19 <?php
20}
21 
22add_action( 'wp_ajax_nopriv_append_country_prefix_in_billing_phone', 'country_prefix_in_billing_phone' );
23add_action( 'wp_ajax_append_country_prefix_in_billing_phone', 'country_prefix_in_billing_phone' );
24function country_prefix_in_billing_phone() {
25 $calling_code = '';
26 $country_code = isset( $_POST['country_code'] ) ? $_POST['country_code'] : '';
27 if( $country_code ){
28 $calling_code = WC()->countries->get_country_calling_code( $country_code );
29 $calling_code = is_array( $calling_code ) ? $calling_code[0] : $calling_code;
30 }
31 echo $calling_code;
32 die();
33}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

0

auto delete woocommerce product images

Added: 1 year ago

Last Updated: 1 year ago

WooCommerce

AI Verified

2

WooCommerce Automatically Set the Complete Order Status

Added: 1 year ago

Last Updated: 5 hours ago

If you’d like to bypass the on-hold order status which either WooCommerce or the payment gateway the customer uses automatically sets on orders, and make it the Completed order status instead, then th...

WooCommerce

AI Verified

0

WooCommerce Custom Text Metabox For Products

Added: 1 year ago

Last Updated: 1 year ago

By default, WooCommerce allows editing for a range of fields including the product’s weight, height, it’s menu order, it’s price…the list goes on! However, it can sometimes be necessary to allow furth...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WordPress Admin

AI Verified

2

Remove the site health dashboard widget

Added: 1 year ago

Last Updated: 1 year ago

WordPress Admin

AI Verified

2

Remove admin nags

Added: 1 year ago

Last Updated: 1 year ago

Custom function to remove admin notices (remember to edit the classes)

WordPress Admin

AI Verified

1

Disable all update notifications emails

Added: 1 year ago

Last Updated: 1 year ago